#define _CRT_SECURE_NO_WARNINGS 1
#include "Sort.h"

void Test1()
{
	int n = 5000000;
	srand(time(NULL));
	int* a1 = (int*)malloc(sizeof(int) * n);
	int* a2 = (int*)malloc(sizeof(int) * n);
	int* a3 = (int*)malloc(sizeof(int) * n);
	int* a4 = (int*)malloc(sizeof(int) * n);
	int* a5 = (int*)malloc(sizeof(int) * n);
	int* a6 = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		int r = rand() + i;
		a1[i] = r;
		a2[i] = r;
		a3[i] = r;
		a4[i] = r;
		a5[i] = r;
		a6[i] = r;
	}

	int begin1 = clock();
	//InsertSort(a1, n);
	int end1 = clock();

	int begin2 = clock();
	HeapSort(a2, n);
	int end2 = clock();

	int begin3 = clock();
	//BubbleSort(a3, n);
	int end3 = clock();

	int begin4 = clock();
	ShellSort(a4, n);
	int end4 = clock();

	int begin5 = clock();
	//SelectSort(a5, n);
	int end5 = clock();

	int begin6 = clock();
	QuickSort(a6, 0, n - 1);
	int end6 = clock();

	printf("InsertSort:%d\n", end1 - begin1);
	printf("HeapSort:%d\n", end2 - begin2);
	printf("BubbleSort:%d\n", end3 - begin3);
	printf("ShellSort:%d\n", end4 - begin4);
	printf("SelectSort:%d\n", end5 - begin5);
	printf("QuickSort:%d\n", end6 - begin6);
}

void Test2()
{
	int n = 10;
	srand(time(NULL));
	int* a = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		int r = (rand() + i) % 100 + 1;
		a[i] = r;
	}
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
	QuickSortByThree_way(a, 0,n-1);
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");

	free(a);
	a = NULL;
	return 0;
}

void Test3()
{
	int arr[] = { 16 ,48, 24 ,70 ,28, 91, 58 ,85 ,23,17 };
	int n = sizeof(arr) / sizeof(arr[0]);
	QuickSortByThree_way(arr, 0,n-1);
	for (int i = 0; i < n; i++)
	{
		printf("%d ", arr[i]);
	}
}

void Test4()
{
	int n = 10;
	srand(time(NULL));
	int* a1 = (int*)malloc(sizeof(int) * n);
	int* a2 = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		int r = (rand() + i) % 100 + 1;
		a1[i] = r;
		a2[i] = r;
	}
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a1[i]);
	}
	printf("\n");
	HeapSort(a1, n);
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a1[i]);
	}
	printf("\n");
	SelectSort(a2, n);
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a1[i]);
	}
	printf("\n");
}

void Test5()
{
	int n = 100000;
	srand(time(NULL));
	int* a1 = (int*)malloc(sizeof(int) * n);
	int* a2 = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		int r = (rand() + i) % 100 + 1;
		a1[i] = r;
		a2[i] = r;
	}
	int begin1 = clock();
	ShellSort(a1, n);
	int end1 = clock();

	int begin2 = clock();
	QuickSort(a1, 0, n - 1);
	int end2 = clock();

	int begin3 = clock();
	QuickSort(a2, 0, n - 1);
	int end3 = clock();

	printf("ShellSort:%d\n", end1 - begin1);
	printf("QuickSort1:%d\n", end2 - begin2);
	printf("QuickSort2:%d", end3 - begin3);
}


int main()
{
	for (int i = 0; i < 10; i++)
	{
		Test2();
		printf("\n");
		Sleep(1000);
	}
	//Test3();
}